package com.cool.controller;

import java.util.concurrent.CompletableFuture;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.cool.dto.request.SendMailRequest;
import com.cool.dto.response.CommonResponse;
import com.cool.service.MailService;
import com.cool.util.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 邮件服务
 * 
 * @author bian
 * @date 2021-05-27
 */
@RestController
@Slf4j
public class MailController {
    @Autowired
    private MailService mailService;

    /**
     * 发送邮件
     * 
     * @param sendMailRequest 发送邮件请求
     * @return 成功相应
     */
    @PostMapping(value = "/mail/send")
    public CommonResponse sendMail(@RequestBody SendMailRequest sendMailRequest) {
        CommonResponse commonResponse = new CommonResponse();
        ResultUtil.setSuccessResponse(commonResponse);
        CompletableFuture.runAsync(() -> mailService.sendMail(sendMailRequest));
        return commonResponse;
    }

}
